package com.CS3340.project;

import java.util.ArrayList;
import java.util.Random;
import java.util.Stack;

// this is a dealer class
// a new shuffled deck of card will be created when the constructor is called
// the .deal() function will return a card when called 


public class dealer {
	private
	ArrayList<card> deck = new ArrayList<card>();
	int[] anArray = new int[52];
	card[] hand;
	
	public dealer(){
		for(int i=0; i<52;i++) //create a array with 52 numbers
			anArray[i]=(i+1);
		shuffle();				//shuffle the array
		create_deck();			// create the deck
	}
	
	void printarray(){ 			//for testing only
		for(int i=0;i<anArray.length;i++)
			System.out.print(anArray[i]+" ");
	}
	
	void shuffle(){
		Random rn = new Random();
		for (int i=0;i<52-1;i++){
			int j = i+(rn.nextInt(52)%((52-i)));
			int temp = anArray[i];
			anArray[i]=anArray[j];
			anArray[j]=temp;
		}
	}
	
	void create_deck(){
		char temp_suit;
		int temp_number;
		
		for (int i=0;i<anArray.length;i++){
			temp_suit = check_suit(anArray[i]);
			temp_number = check_number(anArray[i]);
			card temp_card = new card(temp_suit,temp_number);	//create the temp card
			deck.add(temp_card);								//push temp card to deck
		}
	}
	

	
	char check_suit(int number){
		char result;
		if (number > 0 && number <=13){
			result = 's';
		}
		else if (number >13 && number <=26){
			result = 'h';
		}
		else if (number >26 && number <=39){
			result = 'd';
		}
		else if (number >39 && number <=52){
			result = 'c';
		}
		else 
			result = 99;
		return result;
	}
	
	int check_number(int number){
		int result;
		if (number > 0 && number <=13){
			result = number;
		}
		else if (number >13 && number <=26){
			result = number-13;
		}
		else if (number >26 && number <=39){
			result = number-26;
		}
		else if (number >39 && number <=52){
			result = number-39;
		}
		else 
			result = 99;
		return result;
	}
	
	public card deal(){							
		card temp_card=deck.remove(0);
		return temp_card;
	}
	
	public card[] dealHand() {
		hand = new card[5];
		for (int i = 0; i < 5; i++) {
			hand[i] = this.deal();
		}
		return hand;
	}
}


